<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <script>
    var body = document.querySelector('body');
    var ul = document.createElement('ul');
    var ary = ['张三','李四','王五'];
    for(var i = 0; i <ary.length; i++){
      var li = document.createElement('li');
      li.innerText = ary[i];
      li.style.color = 'green';
      li.style.backgroundColor = 'pink';
      var bg;
      li.onmouseenter = function(){
        bg = this.style.backgroundColor;
        this.style.backgroundColor = 'red';
      }
      li.onmouseleave = function(){
        this.style.backgroundColor = bg;
      }
      ul.appendChild(li);
    }
    body.appendChild(ul);
  </script>
</body>
</html>